package it.demosms.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbit配置类
 * @author 季鑫利
 * @create 2019年11月20日18:03:25
 */
@Configuration
public class RabbitConfig {
    /**
     * 交换机名称
     */
    public static final String TOPIC_EXCHANGE = "topic_exchange";

    /**
     * 队列名称
     */
    public static final String TOPIC_QUEUE = "topic_queue";

    /**
     * 声明交换机
     *
     * @return 交换机
     */
    @Bean("topicExchange")
    public Exchange topicExchange() {
        return ExchangeBuilder.topicExchange(TOPIC_EXCHANGE).durable(true).build();
    }

    /**
     * 声明队列
     *
     * @return 队列
     */
    @Bean("topicQueue")
    public Queue topicQueue() {
        return QueueBuilder.durable(TOPIC_QUEUE).build();
    }

    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding bindQueueExchange(@Qualifier("topicQueue") Queue queue, @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("topic.#").noargs();
    }

}
